

using System;
using MagicApp.Data;
using System.Collections.Generic;
using MagicApp.Data.Creature;

namespace MagicApp.Services
{
	/// <summary>
	/// Description of CardService.
	/// </summary>
	public class CardService : ICardService
	{
		private readonly ICardRepository _repository;
		public CardService(ICardRepository _repository)
		{
			this._repository = _repository;
				
		}

		public Card GetCardById(int Id)
		{
			IList<Card> cards = _repository.GetCards();
			foreach(Card c in cards)
			{
				if(c.CardID == Id) return c;
			}
			return null;
		}
		
		public Card GetCardByName(string name)
		{
			IList<Card> cards = 
                this._repository.GetCards();
			foreach(Card c in cards)
			{
				if(c.CardName.ToLower() == name.ToLower()) return c;
			}
			return null;
		}
		
		public IList<Card> GetCardsForSeries(Series seriesType)
		{
			IList<Card> cards = _repository.GetCards();
			IList<Card> cardsInSeries = new List<Card>();
			Series series = seriesType;
			foreach(Card c in cards)
			{
				if(c.Series == series)
					cardsInSeries.Add(c);
			}
			if(cardsInSeries.Count >= 1)
				return cardsInSeries;
		    return null;
		}

	    public IList<Card> GetCardsByType(CardType _cardType)
	    {
	        IList<Card> cards = _repository.GetCards();
            IList<Card> cardsOfType = new List<Card>();
            foreach(Card c in cards)
            {
                if(c.CardType == _cardType)
                    cardsOfType.Add(c);
            }
            if(cardsOfType.Count >= 1)
                return cardsOfType;
	        return null;
	    }

	   
	}
}
